const moment = require("moment");

//计算当前时间是否处于一个时间段
exports.dateIsBetween = function(start, end){
  let format = "hh:mm:ss";
  //当前时间
  let nowDate = moment().utcOffset(480);

  let dateStart = moment(start, format);
  let dateEnd = moment(end, format);

  let isBetween = nowDate.isBetween(dateStart, dateEnd);
  return isBetween;
}

//获取前几日的日期
exports.getFewDayAge = function(day){
  let today = new Date();
  let targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
  today.setTime(targetday_milliseconds); //注意，这行是关键代码

  let tYear = today.getFullYear();
  let tMonth = today.getMonth();
  let tDate = today.getDate();

  tMonth = doHandleMonth(tMonth + 1);
  tDate = doHandleMonth(tDate);
  return tYear+"-"+tMonth+"-"+tDate;
}

//月份前加零
function doHandleMonth(month){
  let m = month;
  if(month.toString().length == 1){
    m = "0" + month;
  }
  return m;
}
